home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Jotto ][ 1.2 / source / Jotto code ƒ / jotto note pad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  5.6 KB  |  250 lines  |  [TEXT/MMCC]

  1. #include "jotto note pad.h"
  2. #include "jotto environment.h"
  3. #include "environment.h"
  4. #include "util.h"
  5. #include "menus.h"
  6. #include "main.h"
  7. #include "text twiddling.h"
  8. #include "generic window handlers.h"
  9. #include "window layer.h"
  10. #include "program globals.h"
  11.  
  12. #define WINDOW_WIDTH        220
  13. #define    WINDOW_HEIGHT        220
  14. #define kGrowBoxSize        15
  15.  
  16. static    void PutDataIntoTEFields(WindowPtr theWindow);
  17.  
  18. static    short            gOldForegroundTime;        /* stored foreground wait time */
  19. static    CursHandle        gMyIBeamHandle;
  20. static    Handle            gSavedText;
  21. static    short            gSavedSelStart, gSavedSelEnd;
  22. static    Boolean            gSetupDone=FALSE;
  23. static    Boolean            gIsActive=FALSE;
  24.  
  25. void SetupTheNotePad(WindowPtr theWindow)
  26. {
  27.     unsigned char    *titleStr="\pNotes";
  28.     Point            topLeft;
  29.     
  30.     SetWindowWidth(theWindow, WINDOW_WIDTH);
  31.     SetWindowHeight(theWindow, WINDOW_HEIGHT);
  32.     SetWindowType(theWindow, zoomDocProc);
  33.     topLeft.v=qd.screenBits.bounds.bottom-WINDOW_HEIGHT-10;
  34.     topLeft.h=10;
  35.     SetWindowTopLeft(theWindow, topLeft);
  36.     SetWindowHasCloseBox(theWindow, TRUE);
  37.     SetWindowTitle(theWindow, titleStr);
  38.     SetWindowAutoCenter(theWindow, FALSE);
  39.     SetWindowIsFloat(theWindow, FALSE);
  40.     if (gSetupDone)
  41.         return;
  42.     
  43.     gSavedText=0L;
  44.     gSavedSelStart=0;
  45.     gSavedSelEnd=32767;
  46.     gSetupDone=TRUE;
  47.     gMyIBeamHandle=GetCursor(iBeamCursor);
  48. }
  49.  
  50. void ShutDownTheNotePad(void)
  51. {
  52.     if (gSavedText!=0L)
  53.         DisposeHandle(gSavedText);
  54.     if (gMyIBeamHandle!=0L)
  55.         ReleaseResource((Handle)gMyIBeamHandle);
  56. }
  57.  
  58. void OpenTheNotePad(WindowPtr theWindow)
  59. {
  60.     TEHandle        hTE;
  61.     FontInfo        theFontInfo;
  62.     Rect            vScrollBarRect, hScrollBarRect;
  63.     Rect            destRect, viewRect;
  64.     
  65.     hTE=GetWindowTE(theWindow);
  66.     if (hTE==0L)
  67.     {
  68.         SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
  69.             GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
  70.         SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
  71.             GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
  72.         SetWindowVScrollBar(theWindow,
  73.             NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  74.         SetWindowHScrollBar(theWindow,
  75.             NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  76.         
  77.         GetTERect(theWindow, &destRect, TRUE);
  78.         viewRect=destRect;
  79.         hTE=TENew(&destRect, &viewRect);
  80.         SetWindowTE(theWindow, hTE);
  81.         TextFont((**hTE).txFont=geneva);
  82.         TextSize((**hTE).txSize=9);
  83.         TextFace((**hTE).txFace=0);
  84.         GetFontInfo(&theFontInfo);
  85.         (**hTE).fontAscent=theFontInfo.ascent;
  86.         (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  87.         AdjustViewRect(hTE);
  88.         TEAutoView(TRUE, hTE);
  89.         TESetClickLoop((ProcPtr)MyClikLoop, hTE);
  90.         PutDataIntoTEFields(theWindow);
  91.     }
  92.     
  93.     gIsActive=TRUE;
  94.     AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
  95.     AdjustMenus();
  96. }
  97.  
  98. void IdleInNotePad(WindowPtr theWindow, Point mouseLoc)
  99. {
  100.     TEHandle        hTE;
  101.     
  102.     if (gInProgress)
  103.         return;
  104.     
  105.     hTE=GetWindowTE(theWindow);
  106.     TEIdle(hTE);
  107.     
  108.     if (PtInRect(mouseLoc, &((**hTE).viewRect)))
  109.     {
  110.         if (!gCustomCursor)
  111.         {
  112.             SetCursor(*gMyIBeamHandle);
  113.             gCustomCursor=TRUE;
  114.         }
  115.     }
  116.     else
  117.     {
  118.         gCustomCursor=FALSE;
  119.     }
  120. }
  121.  
  122. void KeyPressedInNotePad(WindowPtr theWindow, unsigned char theChar)
  123. {
  124.     TEHandle        hTE;
  125.     ControlHandle    vScrollBar;
  126.     
  127.     hTE=GetWindowTE(theWindow);
  128.     vScrollBar=GetWindowVScrollBar(theWindow);
  129.     
  130.     switch (theChar)
  131.     {
  132.         case 0x09:
  133.             TESetSelect(0, 32767, hTE);
  134.             break;
  135.         default:
  136.             TEKey(theChar, hTE);
  137.     }
  138.     
  139.     AdjustVScrollBar(vScrollBar, hTE);
  140. }
  141.  
  142. void DisposeTheNotePad(WindowPtr theWindow)
  143. {
  144.     unsigned long    theLength;
  145.     TEHandle        hTE;
  146.     
  147.     hTE=GetWindowTE(theWindow);
  148.     if (gSavedText!=0L)
  149.         DisposeHandle(gSavedText);
  150.     if (hTE!=0L)
  151.     {
  152.         gSavedText=NewHandle(theLength=(**hTE).teLength);
  153.         HLock(gSavedText);
  154.         HLock((Handle)hTE);
  155.         Mymemcpy(*gSavedText, *((**hTE).hText), theLength);
  156.         HUnlock(gSavedText);
  157.         HUnlock((Handle)hTE);
  158.         gSavedSelStart=(**hTE).selStart;
  159.         gSavedSelEnd=(**hTE).selEnd;
  160.         TEDispose(hTE);
  161.         SetWindowTE(theWindow, 0L);
  162.     }
  163.     else
  164.     {
  165.         gSavedText=NewHandle(0L);
  166.     }
  167. }
  168.  
  169. void ActivateTheNotePad(WindowPtr theWindow)
  170. {
  171.     gOldForegroundTime=gForegroundWaitTime;
  172.     gForegroundWaitTime=0;
  173.     gIsActive=TRUE;
  174. }
  175.  
  176. void DeactivateTheNotePad(WindowPtr theWindow)
  177. {
  178.     gForegroundWaitTime=gOldForegroundTime;
  179.     gIsActive=FALSE;
  180. }
  181.  
  182. void CopybitsTheNotePad(WindowPtr theWindow, WindowPtr offscreenWindow)
  183. {
  184.     GenericCopybits(theWindow, offscreenWindow, gIsActive);
  185. }
  186.  
  187. void PasteInNotePad(WindowPtr theWindow)
  188. {
  189.     TEHandle        hTE;
  190.     ControlHandle    vScrollBar;
  191.     Handle            scrapHandle;
  192.     long            offset;
  193.     unsigned long    scrapLength;
  194.     unsigned char    *theSource="\pMBDF-A";
  195.     unsigned char    *theTarget="\pProgramming is not a crime.";
  196.     unsigned char    *cheat="\pcheat";
  197.     
  198.     hTE=GetWindowTE(theWindow);
  199.     vScrollBar=GetWindowVScrollBar(theWindow);
  200.     
  201.     scrapHandle=NewHandle(0L);
  202.     if (GetScrap(scrapHandle, 'TEXT', &offset)!=noTypeErr)
  203.     {
  204.         scrapLength=GetHandleSize(scrapHandle);
  205.         if (scrapLength==theSource[0])
  206.         {
  207.             HLock(scrapHandle);
  208.             if (Mymemcompare((Ptr)*scrapHandle, (Ptr)&theSource[1], theSource[0]))
  209.             {
  210.                 ZeroScrap();
  211.                 PutScrap(theTarget[0], 'TEXT', (char*)&theTarget[1]);
  212.             }
  213.         }
  214.         else if ((GameInProgressQQ()) && (scrapLength==cheat[0]))
  215.         {
  216.             HLock(scrapHandle);
  217.             if (Mymemcompare((Ptr)*scrapHandle, (Ptr)&cheat[1], cheat[0]))
  218.             {
  219.                 ZeroScrap();
  220.                 PutScrap(gNumLetters, 'TEXT', gComputerWord);
  221.             }
  222.         }
  223.         
  224.         TEFromScrap();
  225.         TEPaste(hTE);
  226.         TESelView(hTE);
  227.         if (vScrollBar!=0L)
  228.             AdjustVScrollBar(vScrollBar, hTE);
  229.     }
  230.     DisposeHandle(scrapHandle);
  231. }
  232.  
  233. static    void PutDataIntoTEFields(WindowPtr theWindow)
  234. {
  235.     TEHandle            hTE;
  236.     
  237.     hTE=GetWindowTE(theWindow);
  238.     if (hTE==0L)
  239.         return;
  240.     
  241.     if (gSavedText!=0L)
  242.     {
  243.         HLock(gSavedText);
  244.         SetTheText(theWindow, *gSavedText, GetHandleSize(gSavedText));
  245.         HUnlock(gSavedText);
  246.     }
  247.     
  248.     TESetSelect(gSavedSelStart, gSavedSelEnd, hTE);
  249. }
  250.